package com.example.project22_editingmediaplayer;

import java.util.ArrayList;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.example.minimusicdemo.Fragment_playmain;
import com.example.minimusicdemo.Main_play;
import com.example.project22_editingmediaplayer.action.AudioUltility;
import com.example.project22_editingmediaplayer.adapter.RowSong;
import com.example.project22_editingmediaplayer.adapter.RowSongListAlbum;
import com.example.project22_editingmediaplayer.adapter.RowSongplaylistF;
import com.example.project22_editingmediaplayer.objects.SongObject;
import com.example.project22_editingmediaplayer.resource.SongResource;

public class AlbumListDetail extends Activity {
	private RowSongListAlbum Adapter_album;
	ArrayList<SongObject> listAlbumdetail;
	ListView listView_detail;
	AudioUltility audioultility;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listplay_detail);
		listView_detail = (ListView) findViewById(R.id.lv_playlistdetail);

		SongResource.listSong = LayoutAlbums.listAlbumsong;
		Adapter_album = new RowSongListAlbum(LayoutAlbums.listAlbumsong,
				getBaseContext());
		listView_detail.setAdapter(Adapter_album);
		Adapter_album.notifyDataSetChanged();

		listView_detail.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// SongResource.listSong.addAll(LayoutAlbums.listAlbumsong);
				if (MainActivity.mService.getlistsong() != null) {
					SongResource.listSong.get(
							MainActivity.mService.getlastIndex()).set_isplay(
							false);
				}
				SongResource.listSong.get(MainActivity.mService.getIndex())
						.set_isplay(true);
				MainActivity.mService.PlaySong(arg2);
				Adapter_album.notifyDataSetChanged();
			}
		});
		ActionBar actionBar = getActionBar();
		actionBar.setDisplayHomeAsUpEnabled(true);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub

		getMenuInflater().inflate(R.menu.menuplayemotion, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			break;
		case R.id.playall:
			SongResource.listSong = Adapter_album.getAllData();
			Intent intent = new Intent(AlbumListDetail.this, Main_play.class);
			MainActivity.mService.PlaySong(0);
			MainActivity.mService.showNotification(0,
					SongResource.listSong.get(0));
			MainActivity.btnPlay
					.setImageResource(R.drawable.apollo_holo_light_pause);
			MainActivity.namesong.setText(SongResource.listSong.get(0)
					.get_name());
			MainActivity.singer.setText(SongResource.listSong.get(0)
					.get_artist());
			MainActivity.mService.flag_first = false;
			startActivity(intent);
			break;

		default:
			break;
		}
		return false;
	}

}
